using System;
using System.Linq;
using AllIsWell.Core.Models;

namespace AllIsWell.Persistance.Ef
{
    class PageRepository : IPageRepository
    {
        private readonly MyDiary _myDiary;

        public PageRepository(MyDiary myDiary)
        {
            _myDiary = myDiary;
        }

        public Page AddPage(Page page)
        {
            return _myDiary.Pages.Add(page);
        }

        public Page GetPageForToday(int destinyId)
        {
            return _myDiary.Pages
                           .FirstOrDefault(page => page.Destiny.Id == destinyId && 
                                                   page.DateTime == DateTime.Today);
        }
    }
}